from django import forms
from django.db import models
from django.contrib import auth
from django.contrib.auth.models import User
from django.utils import timezone


# Create your models here.

class EvalProject(models.Model):
    id = models.IntegerField(auto_created=True, primary_key=True, blank=True, verbose_name='项目id')
    uid = models.ForeignKey(to=User, related_name='eval_id', verbose_name='用户账号')
    name = models.CharField(max_length=200, verbose_name='项目名')
    ecpect = models.DateTimeField(verbose_name='预期时间')
    begin = models.DateTimeField(verbose_name='开始时间')
    end = models.DateTimeField(verbose_name='终止时间')
    score = models.IntegerField(verbose_name='分数')
    tag = models.IntegerField(verbose_name='标记位')  # 0-项目名称  1-子级名称
    position = models.IntegerField(verbose_name='位置')  # 0-项目  1-ui    2-前端    3-后台

    def __str__(self):
        return str(self.id)

    class Meta:
        db_table = u'eval_project'
        verbose_name_plural = u'评估工程'


class EvalSys(models.Model):
    name = models.CharField(max_length=50, verbose_name='系统名称')

    def __str__(self):
        return str(self.name)

    class Meta:
        # db_table = u'eval_sys'
        verbose_name_plural = u'a.系统表'


class EvalPro(models.Model):
    name = models.CharField(max_length=50, verbose_name='项目名称')
    belong_sys = models.ForeignKey(to=EvalSys, related_name='eval_pro', verbose_name='所属系统', db_index=True)
    manager = models.CharField(max_length=50, verbose_name='项目负责人')
    begin = models.DateTimeField(verbose_name='开始时间', auto_now_add=True)
    estimate = models.DateTimeField(verbose_name='预估时间')
    end = models.DateTimeField(verbose_name='终止时间', default=timezone.now, blank=True)
    kpi = models.FloatField(verbose_name='项目kpi', blank=True, default=0)

    def __str__(self):
        return str(self.name)

    class Meta:
        verbose_name_plural = u'b.项目表'


class EvalFeeSum(models.Model):
    belong_pro = models.ForeignKey(to=EvalPro, related_name='eval_fee_sum', verbose_name='所属项目')
    feedback = models.CharField(max_length=255, verbose_name='项目反馈', blank=True)
    sum_up = models.CharField(max_length=255, verbose_name='项目总结', blank=True)

    def __str__(self):
        return str(self.belong_pro)

    class Meta:
        verbose_name_plural = u'g.项目反馈,总结表'


class EvalDivisionDetail(models.Model):
    belong_pro = models.ForeignKey(to=EvalPro, related_name='eval_division_ditail', verbose_name='所属项目')
    division = models.CharField(max_length=20, verbose_name='部门名称')

    def __str__(self):
        return str(self.division)

    class Meta:
        verbose_name_plural = u'c.部门详情表'


class EvalDivProDetail(models.Model):
    belong_division = models.ForeignKey(to=EvalDivisionDetail, related_name='eval_div_pro_detail', verbose_name='部门名称')
    project = models.CharField(max_length=50, verbose_name='项目名称')

    def __str__(self):
        return str(self.project)

    class Meta:
        verbose_name_plural = u'd.部门分项目详情表'


class EvalDivSubDetail(models.Model):
    belong_div = models.ForeignKey(to=EvalDivProDetail, related_name='eval_div_sub_detial', verbose_name='所属分项目')
    sub_project = models.CharField(max_length=50, verbose_name='子项目名称')
    estimate = models.DateTimeField(verbose_name='预估时间')
    begin = models.DateTimeField(verbose_name='开始时间', auto_now_add=True)
    end = models.DateTimeField(verbose_name='终止时间', default=timezone.now)
    usrname = models.CharField(max_length=50, verbose_name='用户名')
    kpi = models.FloatField(verbose_name='子项目kpi', default=0)

    def __str__(self):
        return str(self.sub_project)

    class Meta:
        verbose_name_plural = u'e.分项目子项目详情表'


class EvalSchDetail(models.Model):
    belong_sub_pro = models.ForeignKey(to=EvalDivSubDetail, related_name='eval_sch_detail', verbose_name='所属子项目')
    schedule = models.CharField(max_length=20, verbose_name='进度')

    def __str__(self):
        return str(self.schedule)

    class Meta:
        verbose_name_plural = u'f.进度详情表'


# class EvalSysDetail(models.Model):
#     # division = models.CharField(max_length=15, verbose_name='部门名称')
#     # div_project = models.CharField(max_length=50, verbose_name='分项目')
#     # sub_project = models.CharField(max_length=50, verbose_name='子项目')
#     sub_project = models.OneToOneField(to=EvalDivSubDetail, verbose_name='所属子项目')
#     estimate = models.DateTimeField(verbose_name='预估时间')
#     begin = models.DateTimeField(verbose_name='开始时间')
#     end = models.DateTimeField(verbose_name='终止时间')
#     # end = models.DateTimeField(verbose_name='终止时间')
#     # schedule = models.CharField(max_length=50, verbose_name='进度')
#     usrname = models.CharField(max_length=50, verbose_name='用户名')
#
#     def __str__(self):
#         return str(self.schedule)
#
#     class Meta:
#         verbose_name_plural = u'项目详情表'
